package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import vo.Address;
import vo.Store;
import dao.LoginDao;
@Repository("ld")
public class LoginDaoImpl implements LoginDao{
	@PersistenceContext(name="un")
	private EntityManager em;
	
	//登录验证
	@Override
	public Store login(String mobile, String sailPasswd) {
		Store sp=null;
		String sql="select sp from Store sp where sp.mobile=:mobile and sp.password=:password ";
		List<Store> ls=em.createQuery(sql)
				.setParameter("mobile",mobile)
				.setParameter("password",sailPasswd)
				
				.getResultList();
		if(ls.isEmpty())
			return null;
		else
			return ls.get(0);
		
	}
	//注册商家
	@Override
	public Integer add(Store sp) {
		addAddress(sp.getAddress());
		em.persist(sp);
		return sp.getId();
	}
	//增添地址信息
	@Override
	public int addAddress(Address address) {
		em.persist(address);
		return address.getAddressid();
	}
	

}
